package HomeWork.hw2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

/**
 * @Author Administrator
 * @Date 2020/5/19 14:11
 **/
@WebServlet("/answerServlet")
public class hw2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        System.out.println("姓名:"+name);
        String[] hobbies = req.getParameterValues("hobby");
        System.out.println("爱好:");
        for (String s:hobbies){
            System.out.println(s+"\t");
        }
        System.out.println();
        System.out.println("获取所有请求参数:");
        Map<String,String[]> map =req.getParameterMap();
        Iterator<String> iterator = map.keySet().iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            String[] values = map.get(key);
            System.out.println(key+":");
            for (String s:values){
                System.out.println(s+"\t");
            }
            System.out.println();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}